package org.example.brave.dubbo.rpc;

import brave.internal.Nullable;
import com.alibaba.dubbo.rpc.Result;
import org.example.brave.rpc.RpcClientResponse;

public class DubboClientResponse extends RpcClientResponse implements DubboResponse {
    final DubboClientRequest request;
    @Nullable final Result result;
    @Nullable final Throwable error;

    DubboClientResponse(DubboClientRequest request, @Nullable Result result, @Nullable Throwable error) {
        if (request == null) throw new NullPointerException("request == null");
        this.request = request;
        this.result = result;
        this.error = error;
    }

    @Override
    public String errorCode() {
        return DubboParser.errorCode(error);
    }

    @Override
    public Throwable error() {
        return error;
    }

    @Override
    public Object unwrap() {
        return result;
    }

    @Override
    public Result result() {
        return result;
    }

    @Override
    public DubboClientRequest request() {
        return request;
    }
}
